<template>
  <div class="counsel">
    <!-- 按钮 -->
    <div class="btns">
      <el-form size="small" inline style="text-align: center">
        <el-form-item label="问题">
          <el-input v-model="param.question"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            size="small"
            type="primary"
            icon="el-icon-search"
            @click="loadCounsels"
            >搜索</el-button>
        </el-form-item>
      </el-form>

      <el-button size="small" type="primary" icon="el-icon-circle-plus-outline" @click="toAddHandler">新增</el-button>
    </div>
    <!-- /按钮 -->
    <!-- {{datasets}} -->
    <!-- 表格 -->
    <el-table size="small" :data="counsels">
         <el-table-column label="序号" type="index" :index="1" width="100"></el-table-column>
         <el-table-column label="问题" prop="question" width="150"></el-table-column>
         <el-table-column label="提问时间" prop="questionTime"></el-table-column>
         <el-table-column label="回复" prop="replay" width="150"></el-table-column>
         <el-table-column label="回复时间" prop="replayTime" width="150"></el-table-column>
         <el-table-column label="状态" prop="status"></el-table-column>
         <el-table-column label="职员ID" prop="professorId"></el-table-column>
         <el-table-column label="用户ID" prop="userId"></el-table-column>
         <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" icon="el-icon-edit" @click="editHandler(scope.row)">修改</el-button>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="deleteHandler(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- /表格 -->
  </div>
</template>
<script>
import { del, get } from "@/utils/request";
export default {
  //页面数据
  data() {
    return {
      param: {},
      counsels: [],
    };
  },
  //页面渲染的时候会调用的函数
  methods: {
    editHandler(row){
      this.$router.push({
        path:"/counsel/create",
        query:row
      })
    },
    deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://localhost:8888/counsel/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadCounsels();
        });
      });
    },
    // 跳转
    toAddHandler() {
      this.$router.push("/counsel/create");
    },

    loadCounsels() {
      let url = "http://localhost:8888/counsel/query";
      get(url, this.param).then((resp) => {
        this.counsels = resp.data;
      });
    },
  },
  created() {
    this.loadCounsels();
  },
};
</script>
<style scoped>
.btns {
  margin-bottom: 0.5em;
}
</style>
